home *** CD-ROM | disk | FTP | other *** search
- /*
- * dtc.c
- *
- * This program illustrates ways in which "dates.obj" and "datenams.c" can be
- * used. In response to its question "Gimme a date: " you can supply a Day
- * Number, a Gregorian date (as mm/dd/yyyy) or a Julian date (as ddd/yyyy).
- * Note that the entire year must be given, not just the last two digits.
- * The prgram will convert Day Numbers and Julian dates to Gregorian, and will
- * validate Gregorian dates, showing you what the back conversion gives.
- * To exit the program, just hit ENTER without entering anything.
- *
- * {c}Copyright 1991 by Crazy Jack
- * All Rights Reserved
- */
-
- #include <stdio.h>
- #include "dates.h"
- #include "datenams.c"
-
- static unsigned int Di, Mi, Yi, Do, Mo, Yo;
- static unsigned long int N;
-
- main()
- {
-
- int Ct;
- static char InputArea[32];
-
- goto AskEm;
-
- do
- {
- if ( Ct == 1 ) /* ----means we got a Day Number. */
- {
- if ( ZDate( N, &Yo, &Mo, &Do ) )
- printf( "Day Number %lu is %s, %s %u, %u,\n"
- " and the Julian date is %u/%u.\n",
- N, DOW( (unsigned int)(N % 7) ),
- MonthName(Mo), Do, Yo,
- YDay( Yo, Mo, Do), Yo );
- else
- printf("Can't convert Day Number %lu.\n", N );
- }
- else if ( Ct == 2 ) /* ----means we got a Julian date. */
- {
- if ( ZDate( N = ZDay( Di, 1, Mi = (unsigned int)(N) ),
- &Yo, &Mo, &Do ) )
- printf("A%svalid Julian date giving Day "
- "Number %lu, which is %.3s, %d %.3s, "
- "%d,\n and the Julian date is %u/"
- "%u.\n", (Mi == Yi) ? " " : "n in",
- N, DOW( (unsigned int)(N % 7) ),
- Do, MonthName(Mo), Yo,
- Yi = YDay( Yo, Mo, Do ), Yo );
- /* That's a pretty messy "printf" statement,*/
- /* and not too portable, The setting of "Yi"*/
- /* by the "YDay" in the last line is to get */
- /* it ready for the (Mi == Yi) ? test in the*/
- /* fourth line, and assumes this order for */
- /* the evaluation, which the Borland com- */
- /* piler uses. This is what C encourages */
- /* in persuit of efficiency. Almost as bad */
- /* as APL, eh? Just be thankful I didn't */
- /* have an excuse go pointer-happy on you! */
- else
- printf("Can't convert resulting Day Number "
- "%lu.\n", N );
- }
- else /*----means we got a Gregorian date.*/
- {
- Mi = (unsigned int)N;
- if ( ZDate( N = ZDay( Yi, Mi, Di ), &Yo, &Mo, &Do ) )
- printf("A%svalid Gregorian date giving Day "
- "Number %lu, which is %s, %u/%u/%u,\n"
- " and the Julian date is %u/%u.\n",
- ( (Mi==Mo) && (Di==Do) ) ? " " : "n in",
- N, DOW( (unsigned int)(N % 7) ), Mo, Do, Yo,
- YDay( Yo, Mo, Do ), Yo);
- else
- printf("Can't convert that date.\n");
- }
- AskEm:
- printf("Gimme a date: "); /* Pop the question. */
- fflush(stdin); /* Read the reply. */
- gets( InputArea );
- /* Convert numbers in reply, */
- } while /* No conversions means we're done. */
- ( (Ct = sscanf( InputArea, "%U%*[^0-9]%u%*[^0-9]%u", &N, &Di, &Yi ))
- && (Ct != EOF) );
-
- return(0);
- }
-